package com.molyfun.parents.activity.store.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.store.view.ProductBriefView;
import com.molyfun.parents.rest.bean.UserProductListResponse;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 *
 */
public class ProductBriefAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context mContext;
    private List<UserProductListResponse.ProductBean> mList;
//    private int mCurrentCategory = StoreTopBar.StoreBarChooseTab.BAR_USING;

    public ProductBriefAdapter(Context context) {
        this.mContext = context;
    }

    public ProductBriefAdapter(Context context, int category) {
        this.mContext = context;
//        this.mCurrentCategory = category;
    }

    public void refreshData(List<UserProductListResponse.ProductBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    public void clearAll(){
        if(mList != null){
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void addAll(List<UserProductListResponse.ProductBean> list) {
        this.mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ProductBriefViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_product_brief_cell, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        final UserProductListResponse.ProductBean productBean = mList.get(position);
        ProductBriefViewHolder productBriefViewHolder = (ProductBriefViewHolder)holder;
        productBriefViewHolder.mProductBriefView.initData(productBean);

    }

    public class ProductBriefViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.product_brief_layout)
        public ProductBriefView mProductBriefView;

        public ProductBriefViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

    @Override
    public int getItemCount() {
        if (mList == null || mList.size() == 0) {
            return 0;
        }
        return mList.size();
    }

}
